/**
 * StringUtil.java - 2013-4-17
 *
 * Licensed Property to China UnionPay Co., Ltd.
 * 
 * (C) Copyright of China UnionPay Co., Ltd. 2010
 *     All Rights Reserved.
 *
 * Project Info: China UnionPay Internet Acquiring Project
 * 
 * Modification History:
 * =============================================================================
 *   Author         Date          Description
 *   ------------ ---------- ---------------------------------------------------
 *        
 * =============================================================================
 */
package com.lijin.workshop.util;

/**
 * Description: 字符串工具类，集成commons的字符串工具类，并提供系统个性化的字符串操作
 *
 * (C) Copyright of China UnionPay Co., Ltd. 2010.
 *
 */
public class StringUtil extends org.apache.commons.lang.StringUtils {
	
	public static final String DEFAULT_SPLITER = ",";

	/**
	 * 将字符串数组trim后拼接成字符串，用默认的分隔符进行分隔
	 * @param strArray
	 * @return
	 */
	public static String StrArrToString(String[] strArr) {
		AssertUtil.isArgumentNull(strArr, "参数strArr为null");
		return StrArrToString(strArr, DEFAULT_SPLITER);
	}
	
	/**
	 * 将数组trim后拼接成字符串,用指定的分隔符进行分隔
	 * @param strArray
	 * @return
	 */
	public static String StrArrToString(String[] strArr, String spliter) {
		AssertUtil.isArgumentNull(strArr, "参数strArr为null");
	
		// 如果未指定分隔符，或者指定的分隔符字符串为空，则用默认的分隔符进行分隔
		if (isBlank(spliter)) {
			spliter = DEFAULT_SPLITER;
		}
		
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < strArr.length; i ++) {
			sb.append(strArr[i].trim());
			if (i < strArr.length - 1) {
				sb.append(spliter);
			}
		}
		return sb.toString();
	}
}
